package top.kpromise.user.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import top.kpromise.user.model.response.VerifyCodeModel;

import java.util.Date;

@Repository
public interface VerifyCodeMapper {

    @Insert("insert into verify_code (receiver, verifyCode, createAt, type) values (#{receiver}, #{code}, #{createAt}, #{type})")
    void saveCode(String receiver, String code, Date createAt, int type);

    @Select("select * from verify_code where receiver = #{receiver} and type = #{type} limit 1")
    VerifyCodeModel findCode(String receiver, int type);

    @Update("update verify_code set verifyCode = #{code}, createAt = #{createAt} where receiver = #{receiver} and type = #{type} limit 1")
    void updateCode(String receiver, int type, String code, Date createAt);

    @Delete("delete from verify_code where receiver = #{receiver} and type = #{type} limit 1")
    void delete(String receiver, int type);
}
